package com.app.server.impl;

import cn.hutool.core.util.StrUtil;
import com.app.common.SystemConstant;
import com.app.mapper.ArticleMapper;
import com.app.model.ArticleModel;
import com.app.server.ArticleService;
import com.app.vo.ArticleVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, ArticleModel> implements ArticleService {
    @Override
    public ArticleVo selectArticleList(Integer page, Integer limit, String keyword) {
        QueryWrapper<ArticleModel> ArticleModelQueryWrapper = new QueryWrapper<>();
        ArticleModelQueryWrapper.eq("status", 1);
        if (StrUtil.isNotBlank(keyword)) {
            ArticleModelQueryWrapper.like("title", keyword);
        }
        Integer count = super.baseMapper.selectCount(ArticleModelQueryWrapper);
        ArticleModelQueryWrapper.orderByDesc("create_time");
        Page<ArticleModel> ArticleModelPage = new Page<>(page, limit);
        Page<ArticleModel> ArticleModelPages = super.baseMapper.selectPage(ArticleModelPage, ArticleModelQueryWrapper);
        List<ArticleModel> ArticleModelList = ArticleModelPages.getRecords();
        ArticleVo vo = new ArticleVo();
        vo.setList(ArticleModelList);
        vo.setCount(count);
        return vo;
    }
}
